<template>
  <div class="spelldeals">
    <div class="top-one">
      <img
        :src="data.pc_image_text"
        alt=""
        @click="goDetail(list[0])"
      >
    </div>
    <div class="top-other">
      <el-carousel
        :interval="5000"
        arrow="always"
        height="29.5rem"
        indicator-position="none"
      >
        <el-carousel-item
          v-for="items in second.count"
          :key="items"
        >
          <div v-if="items > 1">
            <div
              v-for="(item, str) in second.goodsList"
              :key="item.index"
              class="goods-item"
              @click="goDetail(item)"
            >
              <div 
                v-if="str >= (items - 1) * 4 && str < items * 4" 
                style="margin: 0 auto; text-align: center;"
              >
                <img
                  src="../../assets/img/top2@2x.png"
                  alt=""
                  class="top-img"
                >
                <img
                  :src="item.defaultAlbum"
                  alt=""
                  class="goods-img"
                >
                <div class="goods-info">
                  <p class="name">
                    {{ item.pName }}
                  </p>
                  <p class="price">
                    ￥ {{ item.fSalePrice }}
                  </p>
                </div>
              </div>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="more">
      <img
        src="../../assets/img/logo2.png"
        alt=""
        @click="spelldeals"
      >
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  components: {},
  props: {
    data: {
      type: Object,
      // 对象或数组默认值必须从一个工厂函数获取
      default: function () {
        return {};
      },
    },
  },
  data() {
    return {
      list: [],
      coverList: [],
      second: {},
    };
  },
  mounted() {
    this.$api.home.getTopList().then((res) => {
      if (res.code == 1) {
        this.coverList = res.data;
      }
    });
    this.$api.home.sales().then((res) => {
      if (res.code == 1) {
        this.list = res.data;
        this.$set(this.second, "goodsList", res.data);
        this.$set(this.second, "count", Math.ceil(res.data.length / 4));
      }
    });
  },
  methods: {
    spelldeals() {
      this.$router.push({ path: "/top" });
    },
    //跳转商品详情
    goDetail(item) {
      this.$router.push({
        path: "/fruit/detail",
        query: {
          id: item.pid,
          iShopId: item.iShopId
        },
      });
    },
  },
};
</script>

<style scoped lang="scss">
.spelldeals {
  padding: 0 16.19rem;
  margin-top: 2.19rem;
  display: flex;
  flex-direction: column;
  .top-one {
    width: 100%;
    img {
      width: 100%;
    }
  }
  .top-other {
    margin-top: 1.25rem;
    margin-bottom: 1.25rem;
    .el-carousel__item {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      .goods-item {
        width: 20.94rem;
        height: 100%;
        background: #fff;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-around;
        position: relative;
        margin-right: 1.19rem;
        &:nth-child(4n) {
          margin-right: 0;
        }
        .goods-img {
          width: 15rem;
          height: 15rem;
          object-fit: contain;
        }
        .top-img {
          width: 3.94rem;
          height: 3.94rem;
          position: absolute;
          top: 1.25rem;
          left: 1.56rem;
        }
        .goods-info {
          display: flex;
          flex-direction: column;
          text-align: center;
          padding: 0 1rem;
          .name {
            font-size: 1.13rem;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(4, 0, 0, 1);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            width: 18rem;
          }
          .price {
            font-size: 1.5rem;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(243, 64, 111, 1);
            margin-top: 0.94rem;
          }
        }
      }
    }
  }
  .more {
    height: 2.5rem;
    background: rgba(0, 0, 0, 1);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0 1.44rem;
    img {
      width: 7.38rem;
      cursor: pointer;
    }
  }
}
</style>

